package tij4.concurrent.exercise.ex20;

import tij4.concurrent.pojo.LiftOff;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class Ex20 {
    /*
        修改了 CacheThreadPool 使所有的任务在结束前都将收到一个interrupt()
     */
    public static void main(String[] args) throws InterruptedException {
        System.out.println("Using Liftoff()");
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 5; i++) {
            Future<?> future = executorService.submit(new LiftOff());
            future.cancel(true);
        }
        executorService.shutdownNow();
        if(!executorService.awaitTermination(250, TimeUnit.MILLISECONDS)){
            System.out.println("Some tasks were not terminated");
        }
    }
}
